//#Author:bin
// -*- charset = utf-8 -*-
// @time:2022/2/17 16:18
// @Author:bfl91
// @file : home.js
// @Software:WebStorm
import http from "../api/http";
export default {
    namespaced: true,
    state: {
        list: [] || JSON.parse(localStorage.getItem('list')),//轮播图
        navlist: [] || JSON.parse(localStorage.getItem('navlist')),//nav
        floorlist: [] || JSON.parse(localStorage.getItem('floorlist'))//楼层图
    },
    mutations: {
        setbnner(state, list) {
            state.list = list
        },
        setnav(state, list) {
            state.navlist = list
        },
        setfloorlist(state, list) {
            state.floorlist = list
        }
    },
    actions: {
        //获取首页数据
        getbanner(context) {
            if(context.state.list.length>0){
                return
            }
            http('home/swiperdata').then(res => {
                localStorage.setItem('list', JSON.stringify(res.message))
                context.commit('setbnner', res.message)
            });
        },
        // 获取分类nav
        getfloor(context) {
            if(context.state.navlist.length>0){
                return
            }
            http('home/catitems').then(res => {
                localStorage.setItem('navlist', JSON.stringify(res.message))
                context.commit('setnav', res.message)
            });
        },
        //获取首页数据
        getnav(context) {
            if(context.state.floorlist.length>0){
                return
            }
            //获取楼层图
            http('home/floordata').then(res => {
                localStorage.setItem('floorlist', JSON.stringify(res.message))
                console.log(res.message)
                context.commit('setfloorlist', res.message)
            });
        }
    }
}